<template>
    <div>
        <h1>添加科室</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">药品名称</td>
                    <td>
                        <input type="text" v-model="info.Uname">
                    </td>
                </tr>
                <tr>
                    <td align="right">科室</td>
                    <td>
                        <select v-model="info.Tid">
                            <option :value="item.Tid" v-for="item in gettype">{{ item.Tname }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">用药日期</td>
                    <td>
                        <input type="date" v-model="info.Udate">
                    </td>
                </tr>
                <tr>
                    <td align="right">病人姓名</td>
                    <td>
                        <input type="text" v-model="info.Uxing">
                    </td>
                </tr>
                <tr>
                    <td align="right">病房号码</td>
                    <td>
                        <input type="text" v-model="info.Uhao">
                    </td>
                </tr>
                <tr>
                    <td align="right">用药状态</td>
                    <td>
                        <input type="radio" v-model="info.Ustate" :value="false" name="state">未开始
                        <input type="radio" v-model="info.Ustate" :value="true" name="state">已完成
                    </td>
                </tr>
                <tr>
                    <td align="right">配药医生</td>
                    <td>
                        <input type="text" v-model="info.Uuname">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="修改" class="btn btn-info" @click="updateuse">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue'
import axios from 'axios'
import { useRoute,useRouter } from 'vue-router';
import { isTemplateExpression } from 'typescript';
const route = useRoute();
const router = useRouter();
let info:any=reactive({
    "Uname": "",
    "Tid": "",
    "Udate": "",
    "Uxing": "",
    "Uhao": "",
    "Ustate": "",
    "Uuname": "",
})

let gettype:any=ref([]);



onMounted(()=>{
    BindType();
    FindUse();
})

const FindUse=()=>{
    axios({
        url:"/api/Use/FindUse",
        method:"get",
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info,res.data);

    })
    .catch((err)=>{
        console.log(err);
    })
}
const BindType=()=>{
    axios({
        url:"/api/Use/BindType",
        method:"get",
    })
    .then((res)=>{
        console.log(res);
        gettype.value = res.data;
    })
    .catch((err)=>{
        console.log(err);
    })
}

const updateuse=()=>{
    axios({
        url:"/api/Use/UpdateUse",
        method:"put",
        data:info
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert("修改成功");
        return;
    }
    else
    {
        alert("修改失败");
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
    })
}

</script>

<style scoped>

</style>